package com.xinfu.newproject.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.xinfu.newproject.R;
import com.xinfu.newproject.adapter.setting.SettingAdapter;
import com.xinfu.newproject.base.BaseActivity;
import com.xinfu.newproject.interface_.SwichFragmentInterface;
import com.xinfu.newproject.util.SPUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity implements SwichFragmentInterface {

    @BindView(R.id.activity_setting_rv)
    RecyclerView mRecyclerView;

    @BindView(R.id.footer_setting_tv)
    TextView exitedTv;

    private SettingAdapter settingAdapter;

    private FragmentManager fragmentManager;
    public final static int FRAGMENT_ZERO = 0;
    public final static int FRAGMENT_ONE = 1;
    public final static int FRAGMENT_TWO = 2;
    public final static int FRAGMENT_THREE = 3;
    public final static int FRAGMENT_ACUUOUNT_THREE = 203;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        registerBack();
        initViewBind();
        initLisener();
    }

    private void initLisener() {

    }

    private void initViewBind() {
        setActivityTitle("设置");
        fragmentManager = getSupportFragmentManager();
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        settingAdapter = new SettingAdapter(3);
        settingAdapter.openLoadAnimation();
        mRecyclerView.setAdapter(settingAdapter);

        settingAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (position == FRAGMENT_THREE) {

                } else {
                    showFragment(position + 1, position, null);
                }
            }
        });

        mRecyclerView.setAdapter(settingAdapter);
    }

    @OnClick({R.id.footer_setting_tv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.footer_setting_tv:
                SPUtils.clear(this);
                finish();
                break;
        }
    }

    public void showFragment(int index, int type, Bundle bundle) {
        FragmentTransaction ft = fragmentManager.beginTransaction();
        hideFragments(ft);
        //注意这里设置位置
//        position = index;
        Bundle bundle1 = new Bundle();
        bundle1.putInt("type", type);
        Log.i("testOne", type + "");
        switch (index) {
            case FRAGMENT_ZERO:
                break;
            case FRAGMENT_ONE:

                break;
            case FRAGMENT_TWO:


                break;
            case FRAGMENT_ACUUOUNT_THREE:


                break;

        }
        ft.commitAllowingStateLoss();
    }

    /**
     * 隐藏fragment
     *
     * @param transaction
     */
    private void hideFragments(FragmentTransaction transaction) {

    }


    @Override
    public void setSelectedFragment(int fragment, int type) {

    }
}
